import Slider from "ant-design-vue/es/slider";
import "ant-design-vue/lib/slider/style/css";

export default {
  name: "FormSlider",
  props: {
    option: {
      type: Object,
      default() {
        return {};
      }
    },
    value: [Number, String, Array]
  },
  model: {
    prop: "value",
    event: "updata"
  },
  data() {
    return {
      isFocus: false
    };
  },
  directives: {
    focus: {
      update: function(el, { value }) {
        if (value) {
          el.focus();
        }
      }
    }
  },
  computed: {},
  created() {},
  methods: {
    onChange(value) {
      this.$emit("updata", value);
      this.$emit("change", value);
    },
    setFocus(is) {
      this.isFocus = is;
    }
  },
  render() {
    const that = this;
    const props = {
      props: {
        ...this.option.props
      },
      on: {
        change: e => {
          that.onChange(e);
        },
        focus: e => {
          this.$emit("focus", e);
        },
        blur: e => {
          this.isFocus = false;
          this.$emit("blur", e);
        }
      },
      directives: [
        {
          name: "focus",
          value: this.isFocus
        }
      ]
    };
    if (this.value) {
      props.props.value = this.value;
    }

    return <Slider {...props} />;
  }
};
